<template>
  <div>
    <sec-form :formData="formData" :ruleForm="ruleForm" :optionData="optionData" :loadingProp="loadingProp"></sec-form>
  </div>
</template>

<script>
import { upmAssetBatchReportApi } from "api/authApi";
import { getItemSceneTypeApi } from "api/configApi";
export default {
  name: "secBatchOpt",
  props: {
    ids: Array,
  },
  components: {},
  data() {
    return {
      loadingProp: { confirm: false },
      ruleForm: { opt: "10", auditType: "upm_auth", scene: [] },
      optionData: {
        opt: [{ label: "发起审计", value: "10" }],
        auditType: [
          { label: "权限审计", value: "upm_auth" },
          { label: "权限快捷审计", value: "upm_auth_quick" },
        ],
        scene: [],
      },
    };
  },
  created() {
    this.formData = [
      { type: "radio", label: "操作", prop: "opt" },
      {
        type: "radio",
        label: "",
        prop: "auditType",
        change: () => {
          this.ruleForm.scene = [];
          this.monitorRadioChange();
        },
      },
      { type: "checkbox", label: "", prop: "scene" },
      { type: "textarea", label: "备注", prop: "remark" },
      {
        type: "operation",
        style: { "text-align": "right" },
        children: [
          {
            label: "取消",
            click: () => {
              this.$emit("cancel");
            },
          },
          {
            prop: "confirm",
            label: "确定",
            click: () => {
              this.batchReport();
            },
          },
        ],
      },
    ];
  },
  mounted() {
    this.initPage();
  },
  methods: {
    initPage() {
      this.monitorRadioChange();
    },
    // 审计专项改变
    monitorRadioChange() {
      getItemSceneTypeApi({ type: this.ruleForm.auditType }).then((res) => {
        console.log(res);
        res.data.forEach((item) => {
          item["label"] = item.name;
        });
        this.optionData.scene = res.data || [];
      });
    },

    batchReport() {
      this.loadingProp.confirm = true;
      let ruleForm = JSON.parse(JSON.stringify(this.ruleForm));
      let scene = ruleForm.scene.length > 0 ? ruleForm.scene.join(",") : "";
      upmAssetBatchReportApi({ ids: this.ids, ...this.ruleForm, scene }).then((res) => {
        this.loadingProp.confirm = false;
        if (!res) return;
        if (res.code == 0) {
          this.$emit("success");
        }
        //如果是资产打标处理
        if (res.sign == "tag") {
          this.message.success({ message: `成功${res.data}条` });
        } else {
          let { succNums, failNums } = res.data;
          if (failNums == "0") {
            this.message.success({ message: `成功${succNums}条，失败${failNums}条` });
          } else {
            this.message.info({ message: `成功${succNums}条，失败${failNums}条` });
          }
        }
      });
    },
  },
};
</script>
<style scoped lang="scss"></style>
